package com.cat.dataStructure;

import java.util.HashMap;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/continuous-subarray-sum/
 * @create 2025/8/16 15:31
 * @since JDK17
 */

public class Solution27 {
    static HashMap<Integer, Integer> map = new HashMap<>();
    public boolean checkSubarraySum(int[] nums, int k) {
        map.clear();
        map.put(0, -1);
        int n = nums.length, reminder = 0;
        for (int i = 0, idx; i < n; i++) {
            reminder = (reminder + nums[i]);
            if (map.containsKey(reminder)) {
                idx = map.get(reminder);
                if (i - idx + 1 >= 2) {
                    return true;
                }
            } else {
                map.put(reminder, i);
            }
        }

        return false;
    }
}
